<template>
  <div class="businessApplication">
    <FixedOperation>
      <el-row>
        <el-col :span="4" :offset="20" class="flex justify-end">
          <slot></slot>
          <el-button
            type="primary"
            @click="handleSave"
            v-if="!isDisabled"
            :disabled="saveLoading"
            >保存</el-button
          >
          <el-button
            @click="process"
            type="primary"
            plain
            v-if="
              (pageType === 'add' || (pageType === 'edit' && isCanStart)) &&
              notInitiated
            "
            >发起流程</el-button
          >
          <el-button
            @click="viewProcess"
            type="primary"
            plain
            v-if="nowTaskName !== '流程未发起' && !editOrDetail"
            >流程详情</el-button
          >
          <el-button @click="goBack" type="primary" plain>返回</el-button>
        </el-col>
      </el-row>
    </FixedOperation>
    <div class="app-container">
      <title-name title="基本信息" icon="i-carbon-bookmark-filled"></title-name>
      <el-form
        :inline="true"
        :model="formParams"
        ref="baseForm"
        :rules="rules"
        label-width="100px"
        class="mt-15px"
        scroll-to-error
      >
        <el-row>
          <el-col :span="10" :offset="2">
            <el-form-item prop="createName" label="申请人:">
              <el-input
                v-model="formParams.createName"
                placeholder="请输入申请人"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item prop="deptName" label="业务部门:">
              <el-input
                v-model="formParams.deptName"
                placeholder="请输入业务部门"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col :span="10" :offset="2">
            <el-form-item prop="date" label="申请日期:">
              <el-date-picker
                v-model="formParams.date"
                type="date"
                placeholder="请输入申请日期"
                :size="size"
              /> </el-form-item
          ></el-col> -->
          <el-col :span="10" :offset="2">
            <el-form-item prop="orgName" label="申请人单位:">
              <el-input
                v-model="formParams.orgName"
                placeholder="请输入申请人单位"
                disabled
              ></el-input></el-form-item
          ></el-col>
          <el-col :span="10">
            <el-form-item prop="type" label="产品归类:">
              <el-radio-group v-model="formParams.type" :disabled="isDisabled">
                <el-radio label="1">投标项目</el-radio>
                <el-radio label="2">单品销售</el-radio></el-radio-group
              >
            </el-form-item></el-col
          >
        </el-row>
        <el-row>
          <el-col :span="10" :offset="2">
            <el-form-item prop="title" label="标题:">
              <el-input
                v-model="formParams.title"
                placeholder="请输入标题"
              ></el-input
            ></el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item prop="number" label="单据编号:">
              <el-input
                v-model="formParams.number"
                placeholder="请输入单据编号"
              ></el-input> </el-form-item
          ></el-col>
        </el-row>

        <el-row>
          <el-col :span="10" :offset="2">
            <el-form-item prop="fileList" label="附件:">
              <el-upload
                v-model:file-list="formParams.fileList"
                class="upload-demo"
                action="#"
                :http-request="handleFileChange"
                accept=""
                multiple
                :show-file-list="false"
              >
                <el-button
                  type="default"
                  style="font-size: 14px"
                  :disabled="isDisabled"
                  ><el-icon> <UploadFilled /> </el-icon>上传文件</el-button
                >
                <template #tip>
                  <div class="text-14px mt-10px" style="width: 100%">
                    <div v-for="(item, index) in fileList" :key="item.fileId">
                      <a
                        :href="item.url"
                        target="_blank"
                        class="text-#409eff"
                        >{{ item.origFileName }}</a
                      >
                      <el-button
                        text
                        plain
                        @click="delFileName(index)"
                        v-if="!isDisabled"
                        >删除</el-button
                      >
                    </div>
                  </div>
                </template>
              </el-upload>
            </el-form-item></el-col
          >
          <el-col :span="10" v-if="formParams.type == 1">
            <el-form-item prop="project" label="项目:">
              <el-input
                v-model.trim="formParams.project"
                placeholder="请输入项目"
                :disabled="isDisabled"
              ></el-input> </el-form-item
          ></el-col>
        </el-row>
      </el-form>

      <title-name title="产品信息" icon="i-carbon-bookmark-filled"></title-name>
      <ProductInfo
        ref="productInfoRef"
        @updateTableList="updateTableList"
        :details="formParams.voList"
        :isDisabled="isDisabled"
        :pageType="pageType"
        :canEdit="canEdit"
      />
      <div calss="my-15px" v-if="canEdit">
        <title-name title="建议" icon="i-carbon-bookmark-filled"></title-name>
        <el-row class="my-15px">
          <el-col :span="22" :offset="1">
            <el-table :data="suggestList" border>
              <el-table-column
                type="index"
                width="70"
                label="序号"
                align="center"
              />
              <el-table-column
                prop="productModel"
                label="产品型号"
                align="center"
              >
              </el-table-column>

              <el-table-column prop="brand" label="品牌" align="center">
                <template #default="scoped">
                  <el-select
                    v-model="scoped.row.brand"
                    @change="selectBrand(scoped.row)"
                    :disabled="!canEdit"
                  >
                    <el-option
                      v-for="(item, index) in suggestOptions[
                        scoped.row.productModel
                      ]"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </template>
              </el-table-column>

              <el-table-column
                label="产品单价(元)"
                align="center"
                prop="quotation"
              >
              </el-table-column>

              <el-table-column label="产品税率(%)" align="center" prop="tax">
              </el-table-column>

              <el-table-column label="产品总价(元)" align="center">
                <template #default="scoped">
                  {{ calcRowPrice(scoped.row.quotation, scoped) }}
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </div>

      <div v-if="pageType !== 'add'">
        <title-name title="历史建议" icon="i-carbon-bookmark-filled">
        </title-name>
        <el-row class="my-15px">
          <el-col :span="22" :offset="1">
            <el-table :data="historyList" border>
              <el-table-column
                type="index"
                width="70"
                label="序号"
                align="center"
              />
              <el-table-column
                prop="productModel"
                label="产品型号"
                align="center"
              >
              </el-table-column>

              <el-table-column prop="brand" label="品牌" align="center">
              </el-table-column>
              <el-table-column
                label="产品单价(元)"
                align="center"
                prop="quotation"
              >
              </el-table-column>

              <el-table-column label="产品税率(%)" align="center" prop="tax">
              </el-table-column>

              <el-table-column label="产品总价(元)" align="center">
                <template #default="scoped">
                  {{
                    (
                      scoped.row.quotation * (scoped.row.productNum || 0)
                    ).toFixed()
                  }}
                </template>
              </el-table-column>

              <el-table-column label="创建人" align="center" prop="createName">
              </el-table-column>

              <el-table-column
                label="创建日期"
                align="center"
                prop="createTime"
              >
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </div>
    </div>

    <submission-process
      :dialogParam="dialogParam"
      :flowOptions="flowOptions"
      @initiate="handleClose('initiate')"
      @close="handleClose('examine')"
    />
  </div>
</template>

<script setup name="Application">
import useUserStore from '@/store/modules/user'
import ProductInfo from '../AddApplication/productInfo.vue'
import { format } from 'date-fns'
import { uploadFile, delFile } from '@/api/salesManage/contractManage'
import {
  addApplication,
  getApplicationDetail,
  getSuggestionList,
  editSuggestion,
  getApplicationDetailExt
} from '@/api/salesManage/application'
import useTagsViewStore from '@/store/modules/tagsView'
import {
  listProcess,
  getBusinessProStatus,
  getNodeData
} from '@/api/workflow/process'
import SubmissionProcess from '@/businessComponents/SubmissionProcess'

const webWork = new Worker('/webWork.js')
const { proxy } = getCurrentInstance()
const router = useRouter()
const route = useRoute()
const UserStore = useUserStore()
const userInfo = UserStore.userInfo
const tagviewStore = useTagsViewStore()
const props = defineProps({
  id: {
    type: String,
    default: ''
  }
})

const formParams = ref({
  deptId: userInfo.deptId,
  deptName: userInfo.dept.deptName,
  orgName: userInfo.orgIdCn,
  orgId: userInfo.orgId,
  createBy: userInfo.userName,
  createName: userInfo.nickName
})
const rules = ref({
  deptName: [{ required: true, message: '请输入业务部门', trigger: 'blur' }],
  createName: [{ required: true, message: '请输入申请人', trigger: 'blur' }],
  // createTime: [{ required: true, message: '请输入日期', trigger: 'blur' }],
  orgName: [{ required: true, message: '请输入申请人单位', trigger: 'blur' }],
  type: [{ required: true, message: '请输入产品归类', trigger: 'change' }],
  project: [{ required: true, message: '请输入项目', trigger: 'blur' }],
  title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  number: [{ required: true, message: '请输入单据编号', trigger: 'blur' }],
  fileList: [{ required: true, message: '请上传附件', trigger: 'change' }]
})

const goBack = () => {
  tagviewStore.delView(router.currentRoute.value)
  router.push({ path: '/source/sourceModules/applicationList' })
}

const suggestList = ref([])
// 计算总价

function calcRowPrice(item, scoped) {
  console.log(
    proxy.$refs.productInfoRef.tableData[scoped.$index]?.productNum,
    scoped.$index
  )
  const count =
    proxy.$refs.productInfoRef.tableData[scoped.$index]?.productNum || 0
  if (item && count) {
    return (item * count).toFixed(2)
  }
  return ''
}

const tableData = ref([])
function updateTableList(params) {
  // 更新表格数据
  tableData.value = proxy.$refs.productInfoRef.tableData
}

const suggestOptions = ref({})
watch(
  tableData,
  val => {
    suggData.value = val
    val.forEach(v => {
      if (v.productModel) {
        // 更新建议列表
        suggestList.value = val
          .filter(v => v.productModel)
          .map(v => {
            const Vbrand = v.extVoList
            const params = {
              productModel: v.productModel,
              brand: Vbrand.find(l => {
                if (suggestList.value.find(n => n.brand === l.brand)) return l
              })?.brand,
              quotation: Vbrand.find(l => {
                if (suggestList.value.find(n => n.brand === l.brand)) return l
              })?.quotation,
              tax: Vbrand.find(l => {
                if (suggestList.value.find(n => n.brand === l.brand)) return l
              })?.tax
            }
            return params
          })
        console.log(suggestList.value, 'newSugg')
        // suggestList.value = newSugg.map(v => {
        //   const el = suggestList.value.find(
        //     l => l.productModel === v.productModel
        //   )
        //   if (el) {
        //     v = el
        //   }
        //   return v
        // })

        // 更新下拉
        suggestOptions.value[v.productModel] = (v.extVoList || []).map(
          (m, n) => {
            return {
              label: m.brand,
              value: m.brand
            }
          }
        )

        // 产品信息中删除建议中所选品牌 清空数据
        suggestList.value.forEach(v => {
          if (
            v.brand &&
            !suggestOptions.value[v.productModel]?.find(
              l => l.label === v.brand
            )
          ) {
            delete v.brand
            delete v.tax
            delete v.quotation
          }
        })
      }
    })
  },
  { deep: true }
)

// 选择品牌
function selectBrand(row) {
  row.quotation = suggData.value
    .find(v => v.productModel === row.productModel)
    .extVoList.find(v => v.brand === row.brand).quotation
  row.tax = suggData.value
    .find(v => v.productModel === row.productModel)
    .extVoList.find(v => v.brand === row.brand).tax
}

// 附件上传
const fileList = ref([])

function beforeAvatarUpload(rawFile) {
  if (rawFile.size / 1024 / 1024 > 20) {
    proxy.$modal.msgError('单个文件不能超过20MB!')
    return false
  }
  return true
}

async function handleFileChange(params) {
  const checkResult = beforeAvatarUpload(params.file)
  if (!checkResult) return
  let formData = new FormData()
  formData.append('file', params.file)
  try {
    const res = await uploadFile(formData)
    if (res.code === 200 && res.data) {
      fileList.value.push(res.data)
      proxy.$refs.baseForm.clearValidate('fileList')
    }
  } catch (error) {}
}

async function delFileName(index) {
  try {
    proxy.$modal.confirm('是否删除该文件').then(async () => {
      const file = fileList.value[index]
      const res = await delFile(file.fileName)
      if (res.code === 200) {
        fileList.value.splice(index, 1)
        if (fileList.value.length === 0) {
          formParams.value.fileList = []
        }
        proxy.$modal.msgSuccess(res.data)
      }
    })
  } catch (error) {}
}

const handleSave = () => {
  return new Promise((resolve, reject) => {
    proxy.$refs.baseForm.validate(valid => {
      if (valid) {
        if (saveLoading.value) {
          return
        }
        saveLoading.value = true

        const result = proxy.$refs.productInfoRef.checkData()
        const suggResult = suggestList.value.find(v => !v.brand)
        if (
          nowTaskName.value.includes('部门负责人审批') ||
          nowTaskName.value === '流程未发起' ||
          nowTaskName.value.includes('申请人')
        ) {
          if (
            formParams.value.orgId !== '484' &&
            nowTaskName.value.includes('省级部门负责人审批')
          ) {
            console.log('分公司走到省公司部门负责人')
            // saveLoading.value = false
          } else {
            if (suggResult) {
              proxy.$modal.msgError('建议存在未选择内容')
              window.scrollTo({
                top: document.body.scrollHeight,
                behavior: 'smooth'
              })
              saveLoading.value = false
              reject()
              return
            }
          }
        }

        if (!result) {
          saveLoading.value = false
          reject()
          return
        }
        const params = {
          ...formParams.value,
          voList: [...proxy.$refs.productInfoRef.tableData]
        }
        params.fileNames = fileList.value.map(v => v.fileName)
        params.voList.forEach(v => {
          v.extVoList.forEach(n => {
            n.fileNames = n.file.map(v => v.fileName)
          })
        })
        if (nowTaskName.value.includes('部门负责人审批')) {
          params.amount = suggestList.value.reduce((pre, cur) => {
            const num =
              formParams.value.voList.find(
                v => v.productModel === cur.productModel
              )?.productNum || 0
            return pre + cur.quotation * num
          }, 0)
        }
        if (
          formParams.value.orgId !== '484' &&
          nowTaskName.value.includes('省级部门负责人审批')
        ) {
          delete params.amount
        }
        addApplication(params)
          .then(res => {
            proxy.$modal.msgSuccess('保存成功')
            tagviewStore.delView(router.currentRoute.value)
            // if (pageType.value === 'add') {
            const array = []
            suggestList.value.forEach((v, i) => {
              const params = {
                formId: res.data,
                productModel: v.productModel,
                productNum: proxy.$refs.productInfoRef.tableData[i]?.productNum,
                brand: v.brand,
                quotation: v.quotation,
                tax: v.tax,
                processState:
                  pageType.value === 'add' ? '申请人' : nowTaskName.value
              }
              if (v.id) {
                params.id = v.id
              }
              array.push(params)
            })
            // }
            if (
              nowTaskName.value.includes('部门负责人审批') ||
              nowTaskName.value === '流程未发起' ||
              nowTaskName.value.includes('申请人')
            ) {
              if (
                formParams.value.orgId !== '484' &&
                nowTaskName.value.includes('省级部门负责人审批')
              ) {
                console.log('分公司走到省公司部门负责人')
                saveLoading.value = false
              } else {
                saveSugges(array)
              }
            } else {
              saveLoading.value = false
            }

            formParams.value.formId = res.data
            resolve(res.data)
          })
          .catch(err => {
            saveLoading.value = false
            reject()
          })
      }
    })
  })
}
const saveLoading = ref(false)
// 保存建议
async function saveSugges(params) {
  await editSuggestion(params, { processState: nowTaskName.value })
  await getSuggList(params[0].formId)
  saveLoading.value = false
}

async function callbackSave() {
  if (
    nowTaskName.value.includes('部门负责人审批') ||
    nowTaskName.value === '流程未发起' ||
    nowTaskName.value.includes('申请人')
  ) {
    if (
      formParams.value.orgId !== '484' &&
      nowTaskName.value.includes('省级部门负责人审批')
    ) {
      console.log('分公司到省公司')
      return new Promise(resolve => {
        resolve()
      })
    } else {
      return new Promise((resolve, reject) => {
        const params = suggestList.value.map((v, i) => {
          v.isLock = '1'
          if (formParams.value.formId) {
            v.formId = formParams.value.formId
          }
          return v
        })

        editSuggestion(params, { processState: nowTaskName.value })
          .then(res => {
            // proxy.$modal.msgSuccess('保存成功')
            resolve()
          })
          .catch(err => {
            reject({ message: '建议保存失败' })
          })
      })
    }
  } else {
    return new Promise(resolve => {
      resolve()
    })
  }
}

const isDisabled = ref(false)
const pageType = ref('add')
const isFirst = ref(true)
const notInitiated = ref(true)
const nowTaskName = ref('流程未发起')
const canEdit = ref(true)

const suggData = ref()
watch(
  suggData,
  val => {
    console.log(val, 'val2', suggData.value)
  },
  { deep: true }
)
const processState = ref('')
async function init() {
  const id = route.query.formId || props.id
  if (id) {
    const nodeData = await getNodeData(id)
    isFirst.value = nodeData.data === null || nodeData.data.isFirst === 'Y'
    nowTaskName.value = nodeData.data?.nowTaskName || '流程未发起'
    if (nodeData.data && !nodeData.data.nowTaskName) {
      nowTaskName.value = '流程已完结'
    }
    notInitiated.value = isFirst.value || nowTaskName.value === '流程未发起'
    if (location.href.includes('applicationEdit')) {
      pageType.value = 'edit'
    }

    const extResult = await getExtDetails(id)
    console.log(suggData.value, 123)
    getApplicationDetail({ formId: id })
      .then(async res => {
        processState.value = res.data.processState
        // formParams.value = { ...res.data, voList: extResult }
        // formParams.value.voList = extResult
        // formParams.value.fileList = res.data.sysAttachFiles
        fileList.value = res.data.sysAttachFiles
        suggData.value = extResult //res.data.voList
        const history = await getHistoryList(id)
        const suggList = await getSuggList(id)
        // historyList.value = history
        webWork.postMessage([
          JSON.stringify(res.data),
          JSON.stringify(extResult),
          JSON.stringify(history),
          JSON.stringify(suggList)
        ])
        webWork.onmessage = function (e) {
          const backData = JSON.parse(e.data)
          formParams.value = backData.data
          historyList.value = backData.historyList
          suggestList.value = backData.suggList
          // updateTableList()
        }
        canEdit.value =
          nodeData.data?.fieldDisabled === 'Y' ||
          nowTaskName.value === '流程未发起' ||
          nowTaskName.value.includes('申请人') ||
          isFirst.value

        if (location.href.includes('applicationDetail')) {
          canEdit.value = false
          isDisabled.value = true
        }

        if (
          location.href.includes('/process/workDetail') &&
          (nowTaskName.value === '流程未发起' ||
            nowTaskName.value.includes('申请人'))
        ) {
          isDisabled.value = false
        }
        if (
          res.data.orgId !== '484' &&
          nowTaskName.value.includes('省级部门负责人审批')
        ) {
          canEdit.value = false
        }

        extResult.forEach(v => {
          suggestOptions.value[v.productModel] = (v.extVoList || []).map(
            (m, n) => {
              return {
                label: m.brand,
                value: m.brand
              }
            }
          )
        })

        console.log(res, suggestOptions.value, 1233)
      })
      .catch(err => {
        console.log(err, 'err')
        const timer = setTimeout(() => {
          clearTimeout(timer)
          saveLoading.value = false
        }, 1000)
      })
    if (location.href.includes('applicationDetail') || !notInitiated.value) {
      isDisabled.value = true
      if (location.href.includes('applicationDetail')) {
        pageType.value = 'detail'
      }
    }
  }
}

function getExtDetails(id) {
  return new Promise(resolve => {
    getApplicationDetailExt({ formId: id }).then(res => {
      resolve(res.data)
    })
  })
}

function getSuggList(id) {
  return new Promise((resolve, reject) => {
    getSuggestionList({
      formId: route.query.formId || id,
      showHistory: '0'
    })
      .then(res => {
        // suggestList.value = res.data
        // if (
        //   !suggestList.value.length &&
        //   formParams.value.voList &&
        //   formParams.value.voList.length
        // ) {
        //   suggestList.value = formParams.value.voList
        //     .filter(v => v.productModel)
        //     .map(v => {
        //       const Vbrand = v.extVoList
        //       const params = {
        //         productModel: v.productModel,
        //         brand: Vbrand.find(l => {
        //           if (suggestList.value.find(n => n.brand === l.brand)) return l
        //         })?.brand,
        //         quotation: Vbrand.find(l => {
        //           if (suggestList.value.find(n => n.brand === l.brand)) return l
        //         })?.quotation,
        //         tax: Vbrand.find(l => {
        //           if (suggestList.value.find(n => n.brand === l.brand)) return l
        //         })?.tax
        //       }
        //       return params
        //     })
        // }
        resolve(res.data)
      })
      .finally(() => {
        const timer = setTimeout(() => {
          clearTimeout(timer)
          saveLoading.value = false
        }, 500)
      })
  })
}

// 获取历史建议
const historyList = ref([])
function getHistoryList(id) {
  return new Promise(resolve => {
    getSuggestionList({
      formId: route.query.formId || id,
      showHistory: '1'
    }).then(res => {
      // historyList.value =
      resolve(res.data)
    })
  })
}

defineExpose({
  handleSave,
  callbackSave
})

// 流程
const projectId = ref()
const proInsId = ref()
const dialogParam = ref({})
const isSave = ref(false) // 保存成功后进行流程
const isCanStart = ref(false)
const isExamine = ref(false)

const flowOptions = ref()
const initFlowFn = async type => {
  // 1.查询该业务是否有流程
  let comRes = await listProcess({ pageNum: 1, pageSize: 9999, category: type })
  flowOptions.value = comRes.rows
  // 2.根据
  if (!flowOptions.value || JSON.stringify(flowOptions.value) == '[]') {
    console.log('未建流程')
    //2.1 没有流程-提示不能新建数据
    proxy.$modal.msgError('该业务没有流程，不能新建')
    handleBack()
  } else if (flowOptions.value.length == 1) {
    console.log('1条流程')
    //2.2 流程只有一个，只有一条流程时，则不弹出框流程提交审核按钮隐藏，直接点击保存
    isExamine.value = false
  } else {
    //2.3多条流程时
  }

  console.log(flowOptions.value, '2222222222222')
}

const getBusinessProStatusFn = async () => {
  let statusRes = await getBusinessProStatus({ businessId: projectId.value })
  if (statusRes.data.canStart) {
    // canStart false时 不能发起，true则可以发起
    isCanStart.value = true
    initFlowFn(32) //业务类型==>流程分类 页面查看
    console.log(32)
  } else {
    isCanStart.value = false
  }
}

const editOrDetail = ref(true)
watch(
  () => props.id,
  val => {
    if (location.href.match(/applicationEdit/)) {
      //编辑页面---------------
      projectId.value = val || route.query.formId
      proInsId.value = route.query.proInsId
      dialogParam.value.businessId = val
      isSave.value = true
      //根据业务查询审批状态
      getBusinessProStatusFn()
    } else if (
      (val && !!location.href.match(/applicationDetail/)) ||
      (val && !!location.href.match(/workDetail/))
    ) {
      pageType.value = 'detail'
      // 待办详情-访问--------------------
      projectId.value = val
      dialogParam.value.businessId = val
      isSave.value = true
      isCanStart.value = false
    } else if (pageType.value === 'add') {
      editOrDetail.value = false
      // 新建页面 ---------------
      // 走业务流程
      initFlowFn(32)
      isExamine.value = true
    }
  },
  {
    immediate: true
  }
)

async function process() {
  let id
  try {
    id = await handleSave()
    if (id) {
      dialogParam.value.visible = true
      dialogParam.value.businessId = id
      dialogParam.value.isfgs = useUserStore().user['orgId'] == '484' ? 0 : 1 //是否省公司
      dialogParam.value.businessName =
        formParams.value.title + '业务产品询价申请'
      dialogParam.value.categoryCode = '32'
    }
  } catch (error) {
    console.log(error)
  }
}

const handleClose = async type => {
  switch (type) {
    case 'examine':
      //弹出框关闭
      dialogParam.value.visible = false
      break
    case 'initiate':
      //审批 发起成功-关闭当前路由
      dialogParam.value.visible = false
      handleBack()
      try {
        await callbackSave()
      } catch (error) {
        console.log(error)
      }
      break
  }
}

const handleBack = () => {
  useTagsViewStore().delView(router.currentRoute.value)
  router.go(-1)
}

function viewProcess() {
  router.push({
    path: '/process/workDetail',
    query: {
      procInsId: proInsId.value || formParams.value.processId,
      //   taskId: row.taskId,
      processed: false,
      isCirculation: processState.value === '审批通过' ? true : undefined
    }
  })
}

onBeforeMount(() => {
  init()
})
</script>

<style scoped lang="scss"></style>
